package com.jiezhuo.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class R {
    private int code;
    private  String msg;
    private boolean success;
    private Map<String,Object> data=new HashMap<String, Object>();
    public static R ok(){
        R resultUtil = new R(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMsg(),ResultCodeEnum.SUCCESS.isSuccess(),new HashMap<String,Object>());
        return resultUtil;
    }

    public static R err(){
        R resultUtil = new R(ResultCodeEnum.ERROR.getCode(),ResultCodeEnum.ERROR.getMsg(),ResultCodeEnum.ERROR.isSuccess(),new HashMap<String,Object>());
        return resultUtil;
    }
//    public static R setResultEnum(ResultCodeEnum resultEnum){
//        R resultUtil = new R(resultEnum.ERROR.getCode(),resultEnum.ERROR.getMsg(),resultEnum.isSuccess(),new HashMap<>());
//
//        return null;
//    }

    public R code(int code){
        this.code=code;
        return  this;
    }
    public R data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
    public R msg(String msg){
        this.msg=msg;
        return  this;
    }

}
